﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;

namespace Algoritmos_de_Ordenação.Algoritmos
{
    public class SelectionSort : DrawingRegion
    {
        public SelectionSort()
        {
        }
        public SelectionSort(TabItem tabItem)
            : base(tabItem, TabType.Selection)
        {
        }
        
        protected override void DoSort()
        {
            int comparisons = 0;
            int swaps = 0;
            
            sorted = false;
            
            int min = 0;
            
            for (int i = 0; i < numElemArray - 1; i++)//3
            {
                min = i;
                updateGBThread(6);    
                
                for (int j = i + 1; j < numElemArray; j++)//7
                {
                    wf ();
                    updateGBThread(8);
                    compareTwoThread ( min, j );
                    
                    comparisons++;
                    updateInformationsThread(SortStatus.Sorting, comparisons, swaps);
                        
                    if (numberArray[j] < numberArray[min])//9
                    {
                        updateGBThread(9);
                        min = j;
                    }
                }

                swaps++;
                compareTwoThread ( i, min );
                updateGBThread(12);
                wf ();
                
                swapTwoThread ( i, min );
                
                int temp = numberArray[i];
                numberArray[i] = numberArray[min];//13
                numberArray[min] = temp;

                updateInformationsThread(SortStatus.Sorting, comparisons, swaps);
            }//for i

            endSorting(comparisons, swaps);
        }//DoSort()
    }
}


